<?php 
//error_reporting(E_ERROR|E_PARSE);
header("Content-Type:text/html; charset=utf-8");
require_once('../config.php');
?>
<?php
$conn = mysqli_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd,$cfg_dbname);
function gethtml($url){
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_REFERER, "http://translate.google.cn/");
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data=curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
//执行命令
if($httpCode !== 200){
      return "err";
    }else{
        return $data;
    }
//关闭URL请求
curl_close($curl);
}
$rss="select * from ph_products where ID='".intval($_GET["id"])."'";
$rsresult=mysqli_query($conn,$rss);
$rsrows=mysqli_fetch_array($rsresult);
$htmlData = $rsrows["content"];
$title = $rsrows["proname"];
$des = $rsrows["sketch"];
$keywords = $rsrows["keywords"];
$lang=$_GET["lang"];
$url="http://translate.google.cn/translate_a/single?client=gtx&sl=auto&tl=".$lang."&dt=t&q=".urlencode($title."|||".$htmlData."|||".$des."|||".$keywords);
$html=json_decode(gethtml($url));
for($i=0;$i<count($html[0]);$i++){
$tt.=$html[0][$i][0];
}
echo $tt;
?>